# Contributor: Łukasz Jendrysik
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=claws-mail
pkgver=3.17.6
pkgrel=0
pkgdesc="GTK+ based e-mail client"
url="https://www.claws-mail.org"
arch="all !x86" # spamassassin
license="GPL-3.0-or-later"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc $pkgname-lang
	$pkgname-plugins-acpi-notifier:_acpi
	$pkgname-plugins-address-keeper:_address_keeper
	$pkgname-plugins-archive:_archive
	$pkgname-plugins-att-remove:_att_remover
	$pkgname-plugins-attatchwarner:_attatchwarner
	$pkgname-plugins-bogofilter:_bogofilter
	$pkgname-plugins-clamd:_clamd
	$pkgname-plugins-fetchinfo:_fetchinfo
	$pkgname-plugins-mailmbox:_mailmbox
	$pkgname-plugins-notification:_notification
	$pkgname-plugins-pdf-viewer:_pdf
	$pkgname-plugins-perl:_perl
	$pkgname-plugins-pgp:_pgp
	$pkgname-plugins-rssyl:_rssyl
	$pkgname-plugins-smime:_smime
	$pkgname-plugins-spamassassin:_spamassassin
	$pkgname-plugins-spamreport:_spamreport
	$pkgname-plugins-tnef:_tnef
	$pkgname-plugins-vcalendar:_vcalendar
	$pkgname-plugins-dillo:_dillo
	$pkgname-plugins-libravatar:_libravatar
	$pkgname-plugins-managesieve:_managesieve
	"

makedepends="gtk+-dev startup-notification-dev enchant2-dev
	libgcrypt-dev libsm-dev gnutls-dev curl-dev dbus-glib-dev
	libetpan-dev openldap-dev gpgme-dev libsoup-dev perl-dev
	poppler-dev libarchive-dev libnotify-dev pinentry-gtk
	spamassassin libical-dev ytnef-dev bogofilter
	automake autoconf libtool
	"
depends="aspell-en"
source="https://www.claws-mail.org/download.php?file=releases/claws-mail-$pkgver.tar.gz
	libetpan-1.9.4.patch
	"

# secfixes:
#   3.17.6-r0:
#     - CVE-2020-15917

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	DATADIRNAME=share ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-static \
		--enable-enchant \
		--enable-gnutls \
		--enable-ldap \
		--disable-crash-dialog \
		--enable-pgpmime-plugin \
		--enable-spamassassin-plugin \
		--enable-bogofilter-plugin \
		--enable-compface \
		--enable-pdf_viewer-plugin \
		--disable-jpilot \
		--disable-bsfilter-plugin \
		--disable-newmail-plugin

	# force disabling of backtrace. the core dump was more useful
	sed -i -e '/HAVE_BACKTRACE/d' config.h

	make
	cd tools
	make
}

package() {
	make DESTDIR="$pkgdir" install
	find tools -maxdepth 1 -type f -and -perm 111 -or -name '*.conf' | while read i; do
		install -D -m755 $i "$pkgdir"/usr/lib/claws-mail/tools/$i
	done
}

_plugin() {
	pkgdesc="$1"
	depends="claws-mail=$pkgver-r$pkgrel $2"
	local _i=
	shift 2
	mkdir -p "$subpkgdir"/usr/lib/claws-mail/plugins
	for _i; do
		mv "$pkgdir"/usr/lib/claws-mail/plugins/${_i}* \
			"$subpkgdir"/usr/lib/claws-mail/plugins/
	done
}

_acpi() {
	_plugin "ACPI notification plugin for Claws Mail" "" acpi_notifier
}

_address_keeper() {
	_plugin "Never forget a typed address in Claws Mail" "" address_keeper
}

_archive() {
	_plugin "Archiving features for Claws Mail" "" archive
}

_att_remover() {
	_plugin "Attachments remover plugin for Claws Mail" "" att_remover
}

_attatchwarner() {
	_plugin "Attachments warner plugin for Claws Mail" "" attachwarner
}

_bogofilter() {
	_plugin "Bogofilter plugin for Claws Mail" "bogofilter" bogofilter
}

_clamd() {
	_plugin "Use Clam AntiVirus to scan messages in Claws Mail" "" clamd
}

_fetchinfo() {
	_plugin "Modify headers of downloaded messages in Claws Mail" "" \
		fetchinfo
}

_mailmbox() {
	_plugin "Add support for mailboxes in mbox format to Claws Mail" "" \
		mailmbox
}

_notification() {
	_plugin "Various ways to notify about new messages in Claws Mail" "" \
		notification
}

_pdf() {
	_plugin "PDF and ghostscript viewer plugin Claws Mail" "" pdf
}

_perl() {
	_plugin "Perl based extended filtering engine for Claws Mail" "" perl
}

_pgp() {
	_plugin "PGP plugin for signing and encrypting with Claws Mail" \
		"pinentry-gtk" pgp
}

_rssyl() {
	_plugin "RSS plugin for Claws Mail" "" rssyl
}

_smime() {
	_plugin "S/MIME support for Claws Mail" "claws-mail-plugins-pgp" smime
}

_spamassassin() {
	_plugin "Spamassassin plugin for Claws Mail" "spamassassin" spamass
}

_spamreport() {
	_plugin "Report spam mail to various places with Claws Mail" "" \
		spamreport
}

_tnef() {
	_plugin "TNEF message parsing for Claws Mail" "" tnef_parse
}

_vcalendar() {
	_plugin "Handling of vCalendar messages in Claws Mail" "" vcalendar
}

_dillo() {
	_plugin "View HTML messages using the dillo web browser" "dillo" dillo
}

_libravatar() {
	_plugin "Displays libravatar/gravatar profiles' images" "" libravatar
}

_managesieve() {
	_plugin "Manage Sieve filters on servers that support ManageSeieve" "" managesieve
}

sha512sums="b09e5811e77c19af0359083a635945e0d94ece085efc8b0936e60743c53b40483bfb35e8b52e3fc5ce1474c04710c0ab382916081c4b798a71fdd474fc901c2a  claws-mail-3.17.6.tar.gz
02d2402d9f63547089d97d7f24b2952271018ed358004e2c740c8c5b3b0f5083d8c5b0bf3f9e77ebcdaabcefce6d096b2aa89969b862c107fdf7a0ff19184c3b  libetpan-1.9.4.patch"
